home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / attclk2.arc / READCLOC.C < prev    next >
C/C++ Source or Header  |  1986-01-09  |  1KB  |  58 lines

  1. /* :ts=8
  2.  *
  3.  *    readclock()
  4.  *
  5.  * read internal clock date and time into the buf
  6.  * structure.  values are adjusted from real time
  7.  * clock format to values usable by the library
  8.  * time functions.
  9.  *
  10.  */
  11.  
  12. #include "setdate.h"
  13. extern    struct tm buf;
  14.  
  15. readclock()
  16. {
  17.         /* the bios rom starts reading the real time clock */
  18.         /* by reading the year port twice.  if this is not */
  19.         /* an incorrect value may be read from the port. */
  20.     inportb(0x7f);
  21.     inportb(0x7f);
  22.  
  23.         /* year */
  24.         /* the real time clock stores the year as a range 0-7 */
  25.         /* from a leap year. */
  26.     buf.tm_year = readport(0x7f) + LEAP_YEAR;
  27.  
  28.         /* month */
  29.         /* the real time clock stores the month as 1-12.  it's */
  30.         /* adjusted here to be 0-11 */
  31.     buf.tm_mon  = readport(0x7c) * 10;
  32.     buf.tm_mon += (readport(0x7b) - 1);
  33.  
  34.         /* day of week */
  35.         /* the real time clock stores the day of week as 1-7. */
  36.         /* it's adjusted here to be 0-6 */
  37.     buf.tm_wday = readport(0x7a) - 1;
  38.  
  39.         /* day */
  40.     buf.tm_mday  = readport(0x79) * 10;
  41.     buf.tm_mday += readport(0x78);
  42.  
  43.         /* hour */
  44.     buf.tm_hour  = readport(0x77) * 10;
  45.     buf.tm_hour += readport(0x76);
  46.  
  47.         /* minute */
  48.     buf.tm_min  = readport(0x75) * 10;
  49.     buf.tm_min += readport(0x74);
  50.  
  51.         /* second */
  52.     buf.tm_sec  = readport(0x73) * 10;
  53.     buf.tm_sec += readport(0x72);
  54.  
  55.         /* hundreths */
  56.     buf.tm_hsec = readport(0x71) * 10;
  57. }
  58.